package org.example.demo.controller.userController;


import io.swagger.annotations.ApiOperation;
import org.example.demo.common.api.CommonResult;
import org.example.demo.service.userService.FavoriteService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 收藏夹相关需求
 */


@Controller
@RequestMapping(value = "/user/favorite")
public class FavoriteController {

    @Autowired
    private FavoriteService favoriteService;

    @ApiOperation("收藏商品（收藏夹商品添加/删除）")
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<Integer> AddToFavorite(Long user_id, Long product_id, Integer opt) {
        int operation_num = opt > 0
                ? favoriteService.addFavorite(user_id, product_id)
                : favoriteService.cancelFavorite(user_id, product_id);
        return CommonResult.success(operation_num);
    }
}
